local SceneBase = require("app.Base.SceneBase")
local SixWhiteMapLayer = require("app.layer.SixWhiteMapLayer")
local MapTool = require("app.tool.MapTool")


local MapEditorScene = class("LoadingScene", SceneBase)

function MapEditorScene:ctor(data)
    MapEditorScene.super.ctor(self,data)
    print("MapEditorScene")

    self.data = data

    self:initUI()    
end

function MapEditorScene:onEnter()
    MapEditorScene.super.onEnter(self)
    self:Initialization()
    
    self.MapLayer = SixWhiteMapLayer.new(self.data)
    self.MapLayer:addTo(self)

    self.MapTool = MapTool.new()
    self.MapTool:addTo(self.memuNode)

    self:AddButtonEvent()
    self:AddDispatchEvent(td.DispatchName.MAP_Click,handler(self,self.OnMapClick))
end

function MapEditorScene:initUI()
    MapEditorScene.super.initUI(self)  
    
    self.memuNode = display.newNode()
    td.AddRelaPos(self.bg,self.memuNode,cc.p(0.85,0.5))

    self.title_text = td.CreateLabel("地图编辑",nil,"24")
    self.title_text:addTo(self.memuNode):move(0,250)

    self.main_btn = td.CreateBtn("返回主菜单")
    self.main_btn:addTo(self.memuNode):move(100,300)

    
    
--    self.angle_xSlider = ccui.Slider:create()
--    self.angle_xSlider:addTo(self.memuNode)

--    self.btn_dian = td.CreateBtn({text = "点",map = td.btnMap.huangse_zheng})
--    self.btn_dian:addTo(self.memuNode):move(-100,-50)
--    self.btn_xian = td.CreateBtn({text = "线",map = td.btnMap.huangse_zheng})
--    self.btn_xian:addTo(self.memuNode):move(0,-50)
--    self.btn_mian = td.CreateBtn({text = "面",map = td.btnMap.huangse_zheng})
--    self.btn_mian:addTo(self.memuNode):move(100,-50)

--    table.insert(self.vChooseTypeBtn,self.btn_dian)
--    table.insert(self.vChooseTypeBtn,self.btn_xian)
--    table.insert(self.vChooseTypeBtn,self.btn_mian)   

--    self.text_Ctrl = td.CreateLabel("Ctrl")
--    self.text_Ctrl:addTo(self.memuNode):move(-50,-50)
--    self.text_Shift = td.CreateLabel("Shift")
--    self.text_Shift:addTo(self.memuNode):move(50,-50)
--    self.text_Alt = td.CreateLabel("Alt")
--    self.text_Alt:addTo(self.memuNode):move(150,-50)

    self.text_dikuaicanshu = td.CreateLabel("地块参数")
    self.text_dikuaicanshu:addTo(self.memuNode):move(0,-100)

    self.text_zuobiao = td.CreateLabel("坐标：")
    self.text_zuobiao:addTo(self.memuNode):move(-50,-150)

    self.text_grid = td.CreateLabel("X:0 Y:0")
    self.text_grid:addTo(self.memuNode):move(50,-150)

    self.text_weizhi = td.CreateLabel("位置：")
    self.text_weizhi:addTo(self.memuNode):move(-50,-200)

    self.text_pos = td.CreateLabel("X:0 Y:0")
    self.text_pos:addTo(self.memuNode):move(50,-200)

    self.text_gaodu = td.CreateLabel("高度：")
    self.text_gaodu:addTo(self.memuNode):move(-50,-250)

    self.text_height = td.CreateLabel("height:0")
    self.text_height:addTo(self.memuNode):move(50,-250)

    self.text_dixing = td.CreateLabel("地形：")
    self.text_dixing:addTo(self.memuNode):move(-50,-300)

    self.text_terrain = td.CreateLabel("terrain:无")
    self.text_terrain:addTo(self.memuNode):move(50,-300)
end

function MapEditorScene:Initialization()
--    self:ClickChooseType(CHOOSE_TYPE.dian)
end

function MapEditorScene:AddButtonEvent()
    td.BtnAddTouch(self.main_btn, handler(self,self.ClickMain)) 
end

function MapEditorScene:ClickMain()
    local scene = require("app.scenes.CreatMapScene").new()
	display.runScene(scene)
end

--function MapEditorScene:ClickRetuenBtn()
--    local scene = require("app.scenes.CreatMapScene").new()
--	display.runScene(scene)
--end

function MapEditorScene:OnMapClick(event)
    local grid = event:GetData().grid
    
    self:ShowMapData(grid)
end

function MapEditorScene:ShowMapData(map_grid)
    local data = self.MapLayer:GetDataForGrid(map_grid)
    dump(data)
    self.text_grid:setString("X:"..data.grid.x.." Y:"..data.grid.y)
    self.text_pos:setString("X:"..data.pos.x.." Y:"..data.pos.y)
    self.text_height:setString("height:"..data.height)
    self.text_terrain:setString("terrain:"..td.TerrainName[data.terrain])
end

function MapEditorScene:Update(dt)
--    self.MapLayer:Updata(dt)end
end



return MapEditorScene